package com.xxl.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;

/**
 * 不需要身份认证的接口
 * @author xxl
 * @date 2023/4/2
 */
@RestControllerAdvice
@Tag(name = "NoAuthenticationApi",description = "不需要身份认证的接口")
@Validated
public interface NoAuthenticationApi<T> {
    /**
     * 注册
     * @param  email 邮箱
     * @param  password  密码
     * @param  username 用户名
     * @return
     */
    @Operation(
            summary = "注册接口",
            description = "用户注册",
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "注册成功",
                            content = @Content(mediaType = "application/json")

                    ),
                    @ApiResponse(
                            responseCode = "403",
                            description = "用户已存在",
                            content = @Content(mediaType = "application/json")
                    ),
                    @ApiResponse(
                            responseCode = "500",
                            description = "未知错误",
                            content = @Content(mediaType = "application/json")
                    )
            },
            parameters = {
                    @Parameter(name = "username",description = "用户名(不能重复)"),
                    @Parameter(name = "password",description = "密码，不能小于6位"),
                    @Parameter(name = "email",description = "邮箱"),
            }
    )
    T register(@NotNull String username, @Length(min = 6,message = "密码最小长度不能小于6位") String password, @Email(message = "邮件格式不对") String email);
    /**
     * 决定是否注册成功，可以用ajax技术
     * @param  registerCode
     * @return T
     */
    @Operation(summary = "验证注册码接口")
    @ApiResponse(description = "注册成功",responseCode = "200")
    @ApiResponse(description = "未知错误",responseCode = "500")
    @Parameter(name = "registerCode",description = "从邮箱获取")
    T registerCode(String registerCode);

    /**
     * 登录
     * @param username
     * @param password
     * @param isRememberMe
     * @return T
     */
    @Operation(summary = "登录接口")
    @ApiResponse(description = "登录成功", responseCode = "200")
    @ApiResponse(description = "账户不存在", responseCode = "404")
    @ApiResponse(description = "账户密码错误", responseCode = "404")
    @Parameter(name = "username",description = "账户名")
    @Parameter(name = "password",description = "账户密码")
    @Parameter(name = "isRememberMe",description = "登录时是否点击了记住我功能")
    T login(@NotNull String username,@NotNull String password,boolean isRememberMe);

    /**
     * 展示主页博客
     * @param
     * @return
     */
    @Operation(summary = "主页展示博客")
    @ApiResponse(responseCode = "200",description = "查询成功")
    @ApiResponse(responseCode = "500",description = "查询失败")
    T homeShowBlog();

    /**
     * 查看博客详细内容
     * @param uuid
     * @return   T
     */
    @Operation(summary = "查询某一个博客")
    @ApiResponse(responseCode = "200",description = "查询成功")
    @ApiResponse(responseCode = "500",description = "查询失败")
    @Parameter(name = "uuid",description = "blog的uuid")
    T queryBlogByUUID(@NotNull String uuid);

    /**
     * 查询一条博客下的所有评论
     * @param uuid
     * @return T
     */
    @Operation(summary = "查询一条博客下的所有评论")
    @ApiResponse(responseCode = "200",description = "查询成功")
    @ApiResponse(responseCode = "500",description = "查询失败")
    @Parameter(name = "uuid",description = "blog的uuid")
    T queryBlogCommentByUUId(String uuid);

    /**
     * 通过标题查询
     * @param title
     * @return T
     */
    @Operation(summary = "通过标题模糊查询相关博客")
    @ApiResponse(responseCode = "200",description = "查询成功")
    @ApiResponse(responseCode = "500",description = "未知错误")
    @Parameter(name = "title",description = "标题")
    T queryBlogByTitle(String title);

    /**
     * 通过用户名模糊查询
     * @param username
     * @return T
     */
    @Operation(summary = "通过用户名模糊查询相关用户")
    @ApiResponse(responseCode = "200",description = "查询成功")
    @ApiResponse(responseCode = "500",description = "未知错误")
    @Parameter(name = "username",description = "用户名")
    T searchUser(String username);
}
